﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Content.aspx.cs" Inherits="Sio.Mdm.Web.Organizacija.Content" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>SIO - MDM :: Organizacija : Content</title>

    <script type="text/javascript">
        function showMenu(node, e) {
            var menu = SkupineContextMenu;
            if (node.browserEvent) {
                this.menuNode = this.getRootNode();
                menu.nodeName = "";
                this.getSelectionModel().clearSelections();
                e = node;
            }
            else {
                this.menuNode = node;
                menu.nodeName = node.text;
                node.select();
            }

            menu.showAt([e.getXY()[0], e.getXY()[1] + 18]);
            e.stopEvent();
        }

        var MyDebug = function(kaj) {
            alert(kaj);

        }

        var osveziDrevoUceci = function(tree) {
            Ext.net.DirectMethods.RefreshUceciMenu({
                success: function(result) {
                    var nodes = eval(result);
                    if (nodes.length > 0) {
                        tree.initChildren(nodes);
                    }
                    else {
                        tree.getRootNode().removeChildren();
                    }
                }
            });
        }

        var osveziDrevoSkupine = function(tree) {
            Ext.net.DirectMethods.RefreshSkupineMenu({
                success: function(result) {
                    var nodes = eval(result);
                    if (nodes.length > 0) {
                        tree.initChildren(nodes);
                    }
                    else {
                        tree.getRootNode().removeChildren();
                    }
                }
            });
        }

        var osveziDrevoStarsi = function(tree) {
            Ext.net.DirectMethods.RefreshStarsiMenu({
                success: function(result) {
                    var nodes = eval(result);
                    if (nodes.length > 0) {
                        tree.initChildren(nodes);
                    }
                    else {
                        tree.getRootNode().removeChildren();
                    }
                }
            });
        }

        var reloadTab = function(params) {
            var tab = TabNavigation.getActiveTab();
            if (tab != null) {
                if (tab.id == 'idTabUceci')
                    addTabUceci(params);
                else if (tab.id == 'idTabStarsi')
                    addTabStarsi(params);
                else if (tab.id == 'idTabPedagOsebje')
                    addTabPedagOsebje(params);
                else if (tab.id == 'idTabNepedagOsebje')
                    addTabNepedagOsebje(params);
            } else {
                Ext.net.DirectMethods.NeizbraniZavihek();
            }
        }

        var addTabUceci = function(params, kaj) {
            addTab("idTabUceci" + kaj, "Učeči - " + kaj, "UceciSeznam.aspx?" + params);
        }

        var addTabSkupina = function(params, kaj) {
            addTab("idTabSkupina" + kaj, "Skupina - " + kaj, "SkupinaSeznam.aspx?" + params);
        }

        var addTabStarsi = function(params, kaj) {
            addTab("idTabStarsi" + kaj, "Starši - " + kaj, "StarsiSeznam.aspx?" + params);
        }
        var addTabPedagOsebje = function(params) {
            addTab("idTabPedagOsebje", "Pedagoško osebje", "OsebjePedagoskoSeznam.aspx?" + params);
        }
        var addTabNepedagOsebje = function(params) {
            addTab("idTabNepedagOsebje", "Nepedagoško osebje", "OsebjeNepedagoskoSeznam.aspx?" + params);
        }
				var addTabExportUceci = function(params) {
            addTab("addTabExportUceci", "Pregled učečih", "PregledUceci.aspx?" + params);
        }
				var addTabExportOsebje = function(params) {
            addTab("addTabExportOsebje", "Pregled osebja", "PregledOsebje.aspx?" + params);
        }


        var addTab = function(id, title, url) {
            tab = TabNavigation.add({
                id: id,
                title: title,
                closable: true,
                autoLoad: {
                    showMask: true,
                    url: url,
                    mode: "iframe",
                    maskMsg: "Nalagam " + title + "..."
                }
            });
            TabNavigation.setActiveTab(tab);
        }
    </script>

    <style type="text/css">
        body, td
        {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 12px;
        }
    </style>
</head>
<body id="mainForm">
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="StoreSolskaLeta" runat="server">
        <reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="LetoId" />
                    <ext:RecordField Name="Naziv" />
                </Fields>
            </ext:JsonReader>
        </reader>
        <listeners>
            <DataChanged Handler="#{ComboLeta}.setValue(2011); osveziDrevoUceci(#{treeClass}); osveziDrevoStarsi(#{treeStarsi}); " />
        </listeners>
    </ext:Store>
    <ext:Menu ID="SkupineContextMenu" runat="server" EnableScrolling="false">
        <items>
            <ext:MenuTextItem ID="NodeName" runat="server" Cls="bold-text" />
            <ext:MenuSeparator />
            <ext:MenuItem ID="MenuItem1" runat="server" Text="Preimenuj" Icon="Pencil">
                <Listeners>
                    <Click Handler="#{treeSkupine}.startEdit(#{treeSkupine}.menuNode, 10);" />
                </Listeners>
            </ext:MenuItem>
            <ext:MenuItem ID="MenuItem2" runat="server" Text="Odstrani" Icon="Delete">
                <Listeners>
                    <Click Handler="#{treeSkupine}.removeNode(#{treeSkupine}.menuNode);" />
                </Listeners>
            </ext:MenuItem>
            <ext:MenuItem ID="MenuItem3" runat="server" Text="Dodaj skupino" Icon="Add">
                <Listeners>
                    <Click Handler="#{treeSkupine}.appendChild(#{treeSkupine}.menuNode, 'Nova skupina');" />
                </Listeners>
            </ext:MenuItem>
        </items>
        <listeners>
            <Show Handler="#{NodeName}.el.update(this.nodeName);" />
        </listeners>
    </ext:Menu>
    <ext:Viewport ID="Viewport1" runat="server" Layout="Border">
        <items>
            <ext:Panel ID="PanelLeviMenu" runat="server" Width="200" Border="false" Region="West"
                Layout="VBox">
                <LayoutConfig>
                    <ext:VBoxLayoutConfig Padding="5" Align="Stretch" />
                </LayoutConfig>
                <Items>
                    <ext:Panel runat="server" ID="solskoLetoPanel" Border="false">
                        <Items>
                            <ext:ColumnLayout ID="ColumnLayout1" runat="server" Split="true" FitHeight="true">
                                <Columns>
                                    <ext:LayoutColumn ColumnWidth="0.4">
                                        <ext:Label ID="Label1" runat="server" Text="Šolsko leto" StyleSpec="text-align:right;  padding-top: 3px;" />
                                    </ext:LayoutColumn>
                                    <ext:LayoutColumn ColumnWidth="0.6">
                                        <ext:ComboBox ID="ComboLeta" runat="server" StoreID="StoreSolskaLeta" Editable="false"
                                            DisplayField="Naziv" ValueField="LetoId" TypeAhead="true" Mode="Local" ForceSelection="true"
                                            EmptyText="Izberi šolsko leto..." Resizable="false" SelectOnFocus="true" AutoHeight="true"
                                            Width="100">
                                            <Listeners>
                                                <Select Handler="osveziDrevoUceci(#{treeClass}); osveziDrevoStarsi(#{treeStarsi}); " />
                                            </Listeners>
                                        </ext:ComboBox>
                                    </ext:LayoutColumn>
                                </Columns>
                            </ext:ColumnLayout>
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="PanelMenu" runat="server" Width="200" Layout="Accordion" Margins="5 0 5 0"
                        Flex="1">
                        <Items>
                            <ext:TreePanel ID="treeClass" Title="Učeči" runat="server" RootVisible="false" AutoScroll="true"
                                Border="false">
                                <TopBar>
                                    <ext:Toolbar>
                                        <Items>
                                            <sio:Button ID="Button3" runat="server" Text="vsi" Icon="UserRed">
                                                <Listeners>
                                                    <Click Handler="addTabUceci('letoid='+#{ComboLeta}.getValue(), 'vsi');" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="Button1" runat="server" Text="dodaj" Icon="Add">
                                                <Listeners>
                                                    <Click Handler="#{AddUceci}.show();" />
                                                </Listeners>
                                            </sio:Button>
                                            <ext:ToolbarFill />
                                            <sio:Button ID="Button7" runat="server" Icon="BulletTogglePlus" ToolTip="Razširi">
                                                <Listeners>
                                                    <Click Handler="#{treeClass}.expandAll();" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="Button8" runat="server" Icon="BulletToggleMinus" ToolTip="Skrči">
                                                <Listeners>
                                                    <Click Handler="#{treeClass}.collapseAll();" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="Button9" runat="server" Icon="Reload" ToolTip="Osveži">
                                                <Listeners>
                                                    <Click Handler="osveziDrevoUceci(#{treeClass});" />
                                                </Listeners>
                                            </sio:Button>
                                        </Items>
                                    </ext:Toolbar>
                                </TopBar>
                            </ext:TreePanel>
                            <ext:TreePanel ID="treeStarsi" Title="Starši" runat="server" RootVisible="false"
                                AutoScroll="true">
                                <TopBar>
                                    <ext:Toolbar>
                                        <Items>
                                            <sio:Button ID="Button2" runat="server" Text="vsi" Icon="UserSuitBlack">
                                                <Listeners>
                                                    <Click Handler="addTabStarsi('letoid='+#{ComboLeta}.getValue(), 'vsi');" />
                                                </Listeners>
                                            </sio:Button>
                                            <ext:ToolbarFill />
                                            <sio:Button ID="Button4" runat="server" Icon="BulletTogglePlus" ToolTip="Razširi">
                                                <Listeners>
                                                    <Click Handler="#{treeStarsi}.expandAll();" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="Button5" runat="server" Icon="BulletToggleMinus" ToolTip="Skrči">
                                                <Listeners>
                                                    <Click Handler="#{treeStarsi}.collapseAll();" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="Button6" runat="server" Icon="Reload" ToolTip="Osveži">
                                                <Listeners>
                                                    <Click Handler="osveziDrevoStarsi(#{treeStarsi});" />
                                                </Listeners>
                                            </sio:Button>
                                        </Items>
                                    </ext:Toolbar>
                                </TopBar>
                            </ext:TreePanel>
                            <ext:TreePanel ID="treeOsebje" Title="Osebje" runat="server" RootVisible="false">
                                <Root>
                                    <ext:TreeNode Expanded="true">
                                        <Nodes>
                                            <ext:TreeNode Text="Pedagoško" Icon="Accept">
                                                <Listeners>
                                                    <Click Handler="addTabPedagOsebje('letoid='+#{ComboLeta}.getValue());" />
                                                </Listeners>
                                            </ext:TreeNode>
                                            <ext:TreeNode Text="Nepedagoško" Icon="Accept">
                                                <Listeners>
                                                    <Click Handler="addTabNepedagOsebje('letoid='+#{ComboLeta}.getValue());" />
                                                </Listeners>
                                            </ext:TreeNode>
                                        </Nodes>
                                    </ext:TreeNode>
                                </Root>
                            </ext:TreePanel>
                            <ext:TreePanel ID="treeSkupine" Title="Skupine" runat="server" RootVisible="false" Icon="Group"
                                EnableDD="true" 
                                Mode="Remote"             
                                AllowLeafDrop="true"
                                ContainerScroll="true" 
                                OnRemoteRename="RenameGroup" 
                                OnRemoteRemove="RemoveGroup"
                                OnRemoteAppend="AppendGroup" 
                                OnRemoteMove="MoveGroup">
                                    <Editors>
                                        <ext:TreeEditor runat="server" CancelOnBlur="true">
                                            <Field>
                                                <ext:TextField runat="server"/>
                                            </Field>
                                        </ext:TreeEditor>
                                    </Editors>
                                    <SelectionSubmitConfig Encode="true" />                                
                                <TopBar>
                                    <ext:Toolbar>
                                        <Items>
                                            <sio:Button ID="btnDodajSkupino" runat="server" Text="DodajSkupino" Icon="Add">
                                                <Listeners>
                                                    <Click Handler="#{treeSkupine}.appendChild(#{treeSkupine}.root, 'Nova skupina');" />
                                                </Listeners>
                                            </sio:Button>
                                            <ext:ToolbarFill />
                                            <sio:Button ID="Button12" runat="server" Icon="BulletTogglePlus" ToolTip="Razširi">
                                                <Listeners>
                                                    <Click Handler="#{treeSkupine}.expandAll();" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="Button13" runat="server" Icon="BulletToggleMinus" ToolTip="Skrči">
                                                <Listeners>
                                                    <Click Handler="#{treeSkupine}.collapseAll();" />
                                                </Listeners>
                                            </sio:Button>
                                            <sio:Button ID="btnReloadSkupine" runat="server" Icon="Reload" ToolTip="Osveži">
                                                <Listeners>
                                                    <Click Handler="osveziDrevoSkupine(#{treeSkupine});" />
                                                </Listeners>
                                            </sio:Button>
                                        </Items>
                                    </ext:Toolbar>
                                </TopBar>
                                <Listeners>
                                    <ContextMenu Fn="showMenu" StopEvent="true" />
                                    <Click  Handler="addTabSkupina('skupinaid='+node.id , node.text);"/>
                                </Listeners>
                            </ext:TreePanel>
                            <ext:TreePanel ID="treePregledi" Title="Pregledi podatkov" runat="server" RootVisible="false" Icon="ReportGo">
                                <Root>
                                    <ext:TreeNode Expanded="true">
                                        <Nodes>
                                            <ext:TreeNode Text="Učeči" Icon="ReportGo">
																							<Listeners>
																								<Click Handler="addTabExportUceci('letoid='+#{ComboLeta}.getValue());" />
                                              </Listeners>
                                            </ext:TreeNode>
                                            <ext:TreeNode Text="Osebje" Icon="ReportGo">
																							<Listeners>
																								<Click Handler="addTabExportOsebje();" />
                                              </Listeners>

                                            </ext:TreeNode>
                                        </Nodes>
                                    </ext:TreeNode>
                                </Root>
                            </ext:TreePanel>                            
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Panel>
            <sio:TabPanel runat="server" ID="TabNavigation" Region="Center">
                <Defaults>
                    <ext:Parameter Name="border" Value="false" Mode="Raw">
                    </ext:Parameter>
                </Defaults>
                <Items>
                </Items>
            </sio:TabPanel>
        </items>
    </ext:Viewport>
 
  <sio:Dialog runat="server" ID="AddUceci"
		Width="600"
		Height="400"
		Url="NovUceci.aspx"
		DialogButtons="SaveClose"
    Title="Dodaj učečega">
		<Parameters>
			<ext:Parameter Name="letoid" Value="ComboLeta.getValue()" Mode="Raw" />
		</Parameters>
	</sio:Dialog>	

    </form>
</body>
</html>
